package com.cf.module.app;

import android.content.Context;

import com.alibaba.android.arouter.facade.Postcard;
import com.alibaba.android.arouter.facade.annotation.Interceptor;
import com.alibaba.android.arouter.facade.callback.InterceptorCallback;
import com.alibaba.android.arouter.facade.template.IInterceptor;
import com.alibaba.android.arouter.launcher.ARouter;

/**
 * @author yangji
 */
@Interceptor(priority = -1, name = "用户是否登录")
public class UserInterceptor implements IInterceptor {
    @Override
    public void process(Postcard postcard, InterceptorCallback callback) {
        if (postcard.getExtra() == 200) {
            if (UserModel.getInstance().isLogin()) {
                callback.onContinue(postcard);
            } else {
                ARouter.getInstance().build("/app/login").navigation();
                callback.onInterrupt(null);
            }
        } else {
            callback.onContinue(postcard);
        }
    }

    @Override
    public void init(Context context) {

    }
}
